#! /bin/sh /usr/share/dpatch/dpatch-run
## 03_misc.dpatch by Mazen Neifer <mazen.neifer@supaero.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: This patch adds contributions of juan.

@DPATCH@
diff -N -c -r mseide-msegui-1.8.orig/contrib/juan/printintf/i386-linux/mseprintintf.pas mseide-msegui-1.8/contrib/juan/printintf/i386-linux/mseprintintf.pas
*** mseide-msegui-1.8.orig/contrib/juan/printintf/i386-linux/mseprintintf.pas	1970-01-01 01:00:00.000000000 +0100
--- mseide-msegui-1.8/contrib/juan/printintf/i386-linux/mseprintintf.pas	2007-11-15 22:57:00.000000000 +0100
***************
*** 0 ****
--- 1,203 ----
+ // Implementation of common printing interface
+ // i386-linux system
+ 
+ unit mseprintintf; // i386-linux
+ 
+ {$ifdef FPC}{$mode objfpc}{$h+}{$INTERFACES CORBA}{$endif}
+ 
+ interface
+ uses sysutils,msestrings,dynlibs;
+ 
+ // Types
+ type
+   cups_option_t = record
+     name: pchar; // Option name
+     value: pchar; // Option value
+   end;
+ 
+   pcups_option_t = ^cups_option_t;
+   ppcups_option_t =^pcups_option_t;
+ 
+   cups_dest_t = record
+     name: pchar; // Printer name
+     instance: pchar;          
+     is_default: longint; // Default printer?
+     num_options: longint; // Number of options
+     options: pcups_option_t; // Options
+   end;
+ 
+   pcups_dest_t = ^cups_dest_t;
+   ppcups_dest_t = ^pcups_dest_t;
+ 
+ const
+   CUPS_LIBRARY = 'libcups.so';
+   
+   // DLL load/unload functions
+   function initializedll(): boolean;
+   procedure finalizedll();
+ 
+ var
+   dllpointer: tlibhandle;
+   
+   // Functions from cups libs
+   cupsgetdests: function(dests: ppcups_dest_t): longint;cdecl;
+   cupsfreedests: procedure(num_dests: longint; dests: pcups_dest_t);cdecl;
+   cupsgetoption: function(name: pchar; num_options: longint; options: pcups_option_t): pchar;cdecl;
+   
+ {$ifdef FPC}
+ {$include ../mseprintintf.inc}
+ {$else}
+ {$include mseprintintf.inc}
+ {$endif}
+ 
+ implementation
+ 
+ {
+ *************************************
+ CUPS DLL load function
+ *************************************
+ }
+ 
+ function initializedll(): boolean;
+ begin
+   initializedll:= false; // Default value
+   
+   dllpointer:= 0;
+   dllpointer:= loadlibrary(CUPS_LIBRARY);
+   
+   if dllpointer <> 0 then
+   begin
+     initializedll:= true;
+   end
+   else
+   begin
+     exit;
+   end;
+   
+   pointer(cupsgetdests):= getprocedureaddress(dllpointer, 'cupsGetDests');
+   pointer(cupsfreedests):= getprocedureaddress(dllpointer, 'cupsFreeDests');
+   pointer(cupsgetoption):= getprocedureaddress(dllpointer, 'cupsGetOption');
+ end;
+ 
+ {
+ *************************************
+ CUPS DLL unload function
+ *************************************
+ }
+ 
+ procedure finalizedll();
+ begin
+   unloadlibrary(dllpointer);
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve printer
+ names list and printer count
+ *************************************
+ }
+ 
+ function pri_getprinterlist: msestringarty;
+ var
+   printercount: longint; // Number of printers
+   printerlist: pcups_dest_t; // List of printers
+   counter: longint;
+ begin
+   result:= nil;
+   if initializedll = false then exit;
+ 
+   printercount:= cupsgetdests(@printerlist);
+   setlength(result, printercount);
+     
+   // Make printer list 
+   for counter:= 0 to high(result) do
+   begin
+     result[counter]:= printerlist[counter].name;
+   end;
+   
+   // Free printer list
+   cupsfreedests(printercount, printerlist);
+   
+   finalizedll;
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve
+ default printer name
+ *************************************
+ }
+ 
+ function pri_getdefaultprinter: msestring;
+ var
+   printercount: longint; // Number of printers
+   printerlist: pcups_dest_t; // List of printers
+   counter: longint;
+ begin
+   result:= '';
+   
+   if initializedll = false then exit;
+   
+   printercount:= cupsgetdests(@printerlist);
+ 
+   for counter:= 0 to printercount - 1 do
+   begin
+     if printerlist[counter].is_default <> 0 then
+     begin
+       result:= printerlist[counter].name;
+       break;
+     end;
+   end;
+   
+   // Free printer list
+   cupsfreedests(printercount, printerlist);
+ 
+   finalizedll;
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve printer
+ properties
+ *************************************
+ }
+ 
+ function pri_getprinterproperties(const printername: msestring;
+                             var properties: printerpropertiesty): boolean;
+ var
+   printercount: longint; // Number of printers
+   printerlist: pcups_dest_t; // List of printers
+   counter: longint;
+ begin 
+   pri_getprinterproperties:= false; // Default value
+   
+   if initializedll = false then exit;
+   
+   printercount:= cupsgetdests(@printerlist);
+ 
+   for counter:= 0 to printercount - 1 do
+   begin
+     if AnsiCompareStr(printerlist[counter].name, printername) = 0 then
+     begin
+       properties.printername:= strpas(printerlist[counter].name);
+       properties.drivername:= strpas(cupsgetoption('printer-make-and-model', 
+          printerlist[counter].num_options, printerlist[counter].options));
+       properties.location:= ''; // Provisional
+       properties.description:= strpas(cupsgetoption('printer-info', 
+            printerlist[counter].num_options, printerlist[counter].options));
+       properties.isdefault:= boolean(printerlist[counter].is_default);
+       properties.isshared:= boolean(strtoint(cupsgetoption('printer-is-shared',
+             printerlist[counter].num_options, printerlist[counter].options)));
+       properties.islocal:= true; // Provisional
+       
+       pri_getprinterproperties:= true; // Printer found
+     end;
+   end;
+   
+   // Free printer list
+   cupsfreedests(printercount, printerlist);
+ 
+   finalizedll;
+ end;
+ 
+ end.
diff -N -c -r mseide-msegui-1.8.orig/contrib/juan/printintf/i386-win32/mseprintintf.pas mseide-msegui-1.8/contrib/juan/printintf/i386-win32/mseprintintf.pas
*** mseide-msegui-1.8.orig/contrib/juan/printintf/i386-win32/mseprintintf.pas	1970-01-01 01:00:00.000000000 +0100
--- mseide-msegui-1.8/contrib/juan/printintf/i386-win32/mseprintintf.pas	2007-11-15 22:57:00.000000000 +0100
***************
*** 0 ****
--- 1,336 ----
+ unit mseprintintf; // i386-win32
+ 
+ {$ifdef FPC}{$mode objfpc}{$h+}{$INTERFACES CORBA}{$endif}
+ 
+ interface
+ uses sysutils,msestrings,dynlibs;
+ 
+ // Types
+ type
+   tdevicemode =  packed record
+     dmDeviceName: array[0..31] of AnsiChar;
+     dmSpecVersion: Word;
+     dmDriverVersion: Word;
+     dmSize: Word;
+     dmDriverExtra: Word;
+     dmFields: DWORD;
+     dmOrientation: smallint;
+     dmPaperSize: smallint;
+     dmPaperLength: smallint;
+     dmPaperWidth: smallint;
+     dmScale: smallint;
+     dmCopies: smallint;
+     dmDefaultSource: smallint;
+     dmPrintQuality: smallint;
+     dmColor: smallint;
+     dmDuplex: smallint;
+     dmYResolution: smallint;
+     dmTTOption: smallint;
+     dmCollate: smallint;
+     dmFormName: Array[0..31] of AnsiChar;
+     dmLogPixels: Word;
+     dmBitsPerPel: DWORD;
+     dmPelsWidth: DWORD;
+     dmPelsHeight: DWORD;
+     dmDisplayFlags: DWORD;
+     dmDisplayFrequency: DWORD;
+     dmICMMethod: DWORD;
+     dmICMIntent: DWORD;
+     dmMediaType: DWORD;
+     dmDitherType: DWORD;
+     dmICCManufacturer : DWORD;
+     dmICCModel: DWORD;
+     dmPanningWidth: DWORD;
+     dmPanningHeight: DWORD;
+   end;
+ 
+   pdevicemode = ^tdevicemode;
+     
+   printer_info_2 = packed Record
+      pServerName: PChar;
+      pPrinterName: PChar;
+      pShareName: PChar;
+      pPortName: PChar;
+      pDriverName: PChar;
+      pComment: PChar;
+      pLocation: PChar;
+      pDevMode: PDeviceMode;
+      pSepFile: PChar;
+      pPrintProcessor: PChar;
+      pDatatype: PChar;
+      pParameters: PChar;
+      pSecurityDescriptor: Pointer;
+      Attributes: DWORD;
+      Priority: DWORD;
+      DefaultPriority: DWORD;
+      StartTime: DWORD;
+      UntilTime: DWORD;
+      Status: DWORD;
+      cJobs: DWORD;
+      AveragePPM: DWORD; 
+   end;
+   
+   pprinter_info_2 = ^printer_info_2;
+   
+   printer_info_4 = packed Record
+     pprintername: pchar; 
+     pservername: pchar;
+     attributes: dword; 
+   end;
+ 
+   pprinter_info_4 = ^printer_info_4;
+ 
+   printer_info_5 = packed Record
+      pprintername: pchar;
+      pportname: pchar;
+      attributes: dword;
+      devicenotselectedtimeout: dword;
+      transmissionretrytimeout: dword;
+   end;
+ 
+   pprinter_info_5 = ^printer_info_5;          
+ 
+ 
+ const
+   PRINT_LIBRARY = 'winspool.drv';
+ 
+   // DLL load/unload functions
+   function initializedll(): boolean;
+   procedure finalizedll();
+ 
+ var
+   dllpointer: tlibhandle;
+   
+   // Functions from gdi libs
+   enumprinters: function(flags: dword; name: pchar; level: dword;
+     pprinterenum: pointer; cbbuf: dword;
+     var pcbneeded, pcreturned: dword): boolean; stdcall;
+ 
+   function getprofilestring(lpappname:pchar;
+     lpkeyname: pchar; lpdefault: pchar; lpreturnedstring: pchar;
+       nsize: dword): dword; stdcall; external 'kernel32' name 'GetProfileStringA';
+   
+ {$ifdef FPC}
+ {$include ../mseprintintf.inc}
+ {$else}
+ {$include mseprintintf.inc}
+ {$endif}
+ 
+ implementation
+ 
+ {
+ *************************************
+ GDI DLL load function
+ *************************************
+ }
+ 
+ function initializedll(): boolean;
+ begin
+   initializedll:= false; // Default value
+   
+   dllpointer:= 0;
+   dllpointer:= loadlibrary(PRINT_LIBRARY);
+   
+   if dllpointer <> 0 then
+   begin
+     initializedll:= true;
+   end
+   else
+   begin
+     exit;
+   end;
+   
+   pointer(enumprinters):= getprocedureaddress(dllpointer, 'EnumPrintersA');
+ end;
+ 
+ {
+ *************************************
+ GDI DLL unload function
+ *************************************
+ }
+ 
+ procedure finalizedll();
+ begin
+   unloadlibrary(dllpointer);
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve printer
+ names list and printer count
+ *************************************
+ }
+ 
+ function pri_getprinterlist: msestringarty;
+ var
+   flags: dword;
+   needed: dword;
+   level: dword;
+   infobuffer: pchar;
+   infoptr: pchar;
+   printercount: dword;
+   counter: longint;
+ begin
+   result:= nil;
+   flags:= 2 or 4;
+   needed:= 0;
+   level:= 4;
+ 
+   if initializedll = false then exit;
+   
+   enumprinters(flags,nil,level,nil,0,needed,printercount);
+   if Needed > 0 then
+   begin
+     getmem(infobuffer,needed);
+     fillchar(infobuffer^,needed,0);
+     
+     enumprinters(flags,nil,level,infobuffer,needed,needed,printercount);
+     infoptr:= infobuffer;
+     setlength(result, printercount);
+     
+     for counter:= 0 to high(result) do
+       begin
+         result[counter]:= (pprinter_info_4(infoptr)^.pprintername);
+         inc(infoptr,sizeof(printer_info_4));
+       end;
+     freemem(infobuffer);
+     
+   end;
+        
+   finalizedll;
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve
+ default printer name
+ *************************************
+ }
+ 
+ function pri_getdefaultprinter: msestring;
+ var
+   flags: dword;
+   level: dword;
+   needed: dword;
+   infobuffer: pchar;
+   printercount: dword;
+   defaultprinter: array[0..79] of char;
+   
+ begin
+   result:= '';
+   
+   if initializedll = false then exit;
+ 
+   flags:= 1;
+   needed:=0;  
+   level:=5;
+ 
+   enumprinters(flags,nil,level,nil,0,needed,printercount);
+   if Needed > 0 then
+   begin
+     // Win95/98/ME
+     getmem(infobuffer,needed);
+     fillchar(infobuffer^,needed,0);
+ 
+     if enumprinters(flags,nil,level,infobuffer,needed,needed,printercount) then
+     begin
+       result:=pprinter_info_5(infobuffer)^.pprintername;
+     end;
+     
+     freemem(infobuffer);
+   end
+   else
+   begin
+     // WinNT4.0/W2K/WXP
+     getprofilestring(pchar('windows'),pchar('device'),pchar(''),
+       defaultprinter,sizeof(defaultprinter));
+     
+     if pos(',',defaultprinter) <> 0 then
+     begin;
+       defaultprinter:= copy(defaultprinter,1,Pos(',',defaultprinter) - 1);
+       result:= strpas(defaultprinter);
+     end;
+   end;
+   
+   finalizedll;
+ end;
+ 
+ {
+ *************************************
+ Function to retrieve printer
+ properties
+ *************************************
+ }
+ 
+ function pri_getprinterproperties(const printername: msestring;
+                       var properties: printerpropertiesty): boolean;
+ var
+   flags: dword;
+   level: dword;
+   needed: dword;
+   infobuffer: pchar;
+   printercount: dword;
+   pprintername: pchar;
+   counter: longint;
+   defaultprinter: msestring;
+   
+ begin
+   result:= false;
+ 
+   flags:= 2 or 4;
+   needed:= 0;
+   level:= 2;
+   
+   defaultprinter:= pri_getdefaultprinter;
+   
+   if initializedll = false then exit;
+   
+   getmem(pprintername,length(printername) + 1);
+   fillchar(pprintername^,length(printername) + 1, 0);
+   strpcopy(pprintername,printername);
+   
+   enumprinters(flags,nil,level,nil,0,needed,printercount);
+   if Needed > 0 then
+   begin
+     getmem(infobuffer,needed);
+     fillchar(infobuffer^,needed,0);
+     
+     enumprinters(flags,nil,level,infobuffer,needed,needed,printercount);
+ 
+     for counter:= 0 to printercount - 1 do
+       begin
+         if strcomp(pprintername, pprinter_info_2(infobuffer)^.pprintername) = 0 then
+         begin
+           properties.printername:= strpas(pprinter_info_2(infobuffer)^.pprintername);
+           properties.drivername:= strpas(pprinter_info_2(infobuffer)^.pdrivername);
+           properties.location:= strpas(pprinter_info_2(infobuffer)^.plocation);
+           properties.description:= strpas(pprinter_info_2(infobuffer)^.pcomment);
+       
+           properties.isdefault:= defaultprinter = 
+                          strpas(pprinter_info_2(infobuffer)^.pprintername);
+           
+           properties.isshared:=
+              pprinter_info_2(infobuffer)^.attributes or 8 = 
+                       pprinter_info_2(infobuffer)^.attributes;
+                       //???? mse
+           
+           properties.islocal:= pprinter_info_2(infobuffer)^.pservername <> nil;
+           
+           result:= true;
+           freemem(infobuffer);
+           freemem(pprintername);
+           finalizedll;
+           exit;
+         end;
+         inc(infobuffer,sizeof(printer_info_2));
+       end;
+ 
+     freemem(infobuffer);
+   end;
+   
+   freemem(pprintername);
+   
+   finalizedll;
+ end;
+ 
+ end.
diff -N -c -r mseide-msegui-1.8.orig/contrib/juan/printintf/mseprintintf.inc mseide-msegui-1.8/contrib/juan/printintf/mseprintintf.inc
*** mseide-msegui-1.8.orig/contrib/juan/printintf/mseprintintf.inc	1970-01-01 01:00:00.000000000 +0100
--- mseide-msegui-1.8/contrib/juan/printintf/mseprintintf.inc	2007-11-15 22:57:00.000000000 +0100
***************
*** 0 ****
--- 1,17 ----
+ // mseprintintf.inc
+ 
+ type
+   printerpropertiesty = record
+     printername: string;
+     drivername: string;
+     location: string;
+     description: string;
+     isdefault: boolean;
+     isshared: boolean;
+     islocal: boolean;
+   end;
+ 
+ function pri_getprinterlist: msestringarty;
+ function pri_getdefaultprinter: msestring;
+ function pri_getprinterproperties(const printername: msestring;
+             var properties: printerpropertiesty): boolean;
